1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module shumate.FileCache; 26 27 private import gio.AsyncResultIF; 28 private import gio.Cancellable; 29 private import glib.Bytes; 30 private import glib.ConstructionException; 31 private import glib.DateTime; 32 private import glib.ErrorG; 33 private import glib.GException; 34 private import glib.Str; 35 private import glib.c.functions; 36 private import gobject.ObjectG; 37 private import shumate.c.functions; 38 public import shumate.c.types; 39 40 41 /** 42 * A cache that stores and retrieves tiles from the file system. It is mainly 43 * used by [class@TileDownloader], but can also be used by custom data 44 * sources. 45 * 46 * The cache will be filled up to a certain size limit. When this limit is 47 * reached, the cache can be purged, and the tiles that are accessed least are 48 * deleted. 49 * 50 * ## ETags 51 * 52 * The cache can optionally store an ETag string with each tile. This is 53 * useful to avoid redownloading old tiles that haven't changed (for example, 54 * using the HTTP If-None-Match header). 55 */ 56 public class FileCache : ObjectG 57 { 58 /** the main Gtk struct */ 59 protected ShumateFileCache* shumateFileCache; 60 61 /** Get the main Gtk struct */ 62 public ShumateFileCache* getFileCacheStruct(bool transferOwnership = false) 63 { 64 if (transferOwnership) 65 ownedRef = false; 66 return shumateFileCache; 67 } 68 69 /** the main Gtk struct as a void* */ 70 protected override void* getStruct() 71 { 72 return cast(void*)shumateFileCache; 73 } 74 75 /** 76 * Sets our main struct and passes it to the parent class. 77 */ 78 public this (ShumateFileCache* shumateFileCache, bool ownedRef = false) 79 { 80 this.shumateFileCache = shumateFileCache; 81 super(cast(GObject*)shumateFileCache, ownedRef); 82 } 83 84 85 /** */ 86 public static GType getType() 87 { 88 return shumate_file_cache_get_type(); 89 } 90 91 /** 92 * Constructor of #ShumateFileCache. 93 * 94 * Params: 95 * sizeLimit = maximum size of the cache in bytes 96 * cacheKey = an ID for the tileset to store/retrieve 97 * cacheDir = the directory where the cache is created. When cache_dir == NULL, 98 * a cache in ~/.cache/shumate is used. 99 * 100 * Returns: a constructed #ShumateFileCache 101 * 102 * Throws: ConstructionException GTK+ fails to create the object. 103 */ 104 public this(uint sizeLimit, string cacheKey, string cacheDir) 105 { 106 auto __p = shumate_file_cache_new_full(sizeLimit, Str.toStringz(cacheKey), Str.toStringz(cacheDir)); 107 108 if(__p is null) 109 { 110 throw new ConstructionException("null returned by new_full"); 111 } 112 113 this(cast(ShumateFileCache*) __p, true); 114 } 115 116 /** 117 * Gets the directory where the cache database is stored. 118 * 119 * Returns: the directory 120 */ 121 public string getCacheDir() 122 { 123 return Str.toString(shumate_file_cache_get_cache_dir(shumateFileCache)); 124 } 125 126 /** 127 * Gets the key used to store and retrieve tiles from the cache. Different keys 128 * can be used to store multiple tilesets in the same cache directory. 129 * 130 * Returns: the cache key 131 */ 132 public string getCacheKey() 133 { 134 return Str.toString(shumate_file_cache_get_cache_key(shumateFileCache)); 135 } 136 137 /** 138 * Gets the cache size limit in bytes. 139 * 140 * Returns: size limit 141 */ 142 public uint getSizeLimit() 143 { 144 return shumate_file_cache_get_size_limit(shumateFileCache); 145 } 146 147 /** 148 * Gets tile data from the cache, if it is available. 149 * 150 * Params: 151 * x = the X coordinate of the tile 152 * y = the Y coordinate of the tile 153 * zoomLevel = the zoom level of the tile 154 * cancellable = a #GCancellable 155 * callback = a #GAsyncReadyCallback to execute upon completion 156 * userData = closure data for @callback 157 */ 158 public void getTileAsync(int x, int y, int zoomLevel, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 159 { 160 shumate_file_cache_get_tile_async(shumateFileCache, x, y, zoomLevel, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 161 } 162 163 /** 164 * Gets the tile data from a completed shumate_file_cache_get_tile_async() 165 * operation. 166 * 167 * @modtime will be set to the time the tile was added to the cache, or the 168 * latest time it was confirmed to be up to date. 169 * 170 * @etag will be set to the data's ETag, if present. 171 * 172 * Params: 173 * etag = a location for the data's ETag, or %NULL 174 * modtime = a location to return the tile's last modification time, or %NULL 175 * result = a #GAsyncResult provided to callback 176 * 177 * Returns: a #GBytes containing the tile data, or %NULL if the tile was not in 178 * the cache or an error occurred 179 * 180 * Throws: GException on failure. 181 */ 182 public Bytes getTileFinish(out string etag, out DateTime modtime, AsyncResultIF result) 183 { 184 char* outetag = null; 185 GDateTime* outmodtime = null; 186 GError* err = null; 187 188 auto __p = shumate_file_cache_get_tile_finish(shumateFileCache, &outetag, &outmodtime, (result is null) ? null : result.getAsyncResultStruct(), &err); 189 190 if (err !is null) 191 { 192 throw new GException( new ErrorG(err) ); 193 } 194 195 etag = Str.toString(outetag); 196 modtime = new DateTime(outmodtime); 197 198 if(__p is null) 199 { 200 return null; 201 } 202 203 return new Bytes(cast(GBytes*) __p, true); 204 } 205 206 /** 207 * Marks a tile in the cache as being up to date, without changing its data. 208 * 209 * For example, a network source might call this function when it gets an HTTP 210 * 304 Not Modified response. 211 * 212 * Params: 213 * x = the X coordinate of the tile 214 * y = the Y coordinate of the tile 215 * zoomLevel = the zoom level of the tile 216 */ 217 public void markUpToDate(int x, int y, int zoomLevel) 218 { 219 shumate_file_cache_mark_up_to_date(shumateFileCache, x, y, zoomLevel); 220 } 221 222 /** 223 * Removes less used tiles from the cache, if necessary, until it fits in 224 * the size limit. 225 * 226 * Params: 227 * cancellable = a #GCancellable 228 * callback = a #GAsyncReadyCallback to execute upon completion 229 * userData = closure data for @callback 230 */ 231 public void purgeCacheAsync(Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 232 { 233 shumate_file_cache_purge_cache_async(shumateFileCache, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 234 } 235 236 /** 237 * Gets the result of an async operation started using 238 * shumate_file_cache_purge_cache_async(). 239 * 240 * Params: 241 * result = a #GAsyncResult provided to callback 242 * 243 * Returns: %TRUE if any tiles were removed, otherwise %FALSE 244 * 245 * Throws: GException on failure. 246 */ 247 public bool purgeCacheFinish(AsyncResultIF result) 248 { 249 GError* err = null; 250 251 auto __p = shumate_file_cache_purge_cache_finish(shumateFileCache, (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 252 253 if (err !is null) 254 { 255 throw new GException( new ErrorG(err) ); 256 } 257 258 return __p; 259 } 260 261 /** 262 * Sets the cache size limit in bytes. 263 * 264 * Params: 265 * sizeLimit = the cache limit in bytes 266 */ 267 public void setSizeLimit(uint sizeLimit) 268 { 269 shumate_file_cache_set_size_limit(shumateFileCache, sizeLimit); 270 } 271 272 /** 273 * Stores a tile in the cache. 274 * 275 * Params: 276 * x = the X coordinate of the tile 277 * y = the Y coordinate of the tile 278 * zoomLevel = the zoom level of the tile 279 * bytes = a #GBytes 280 * etag = an ETag string, or %NULL 281 * cancellable = a #GCancellable 282 * callback = a #GAsyncReadyCallback to execute upon completion 283 * userData = closure data for @callback 284 */ 285 public void storeTileAsync(int x, int y, int zoomLevel, Bytes bytes, string etag, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 286 { 287 shumate_file_cache_store_tile_async(shumateFileCache, x, y, zoomLevel, (bytes is null) ? null : bytes.getBytesStruct(), Str.toStringz(etag), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 288 } 289 290 /** 291 * Gets the success value of a completed shumate_file_cache_store_tile_async() 292 * operation. 293 * 294 * Params: 295 * result = a #GAsyncResult provided to callback 296 * 297 * Returns: %TRUE if the operation was successful, otherwise %FALSE 298 * 299 * Throws: GException on failure. 300 */ 301 public bool storeTileFinish(AsyncResultIF result) 302 { 303 GError* err = null; 304 305 auto __p = shumate_file_cache_store_tile_finish(shumateFileCache, (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 306 307 if (err !is null) 308 { 309 throw new GException( new ErrorG(err) ); 310 } 311 312 return __p; 313 } 314 }